<template>
  <div class="layout">
    <div style="display: flex; justify-content: center">
      <Breadcrumb class="breadcrumb" :crumbs="crumbs"></Breadcrumb>
    </div>
    <div class="content">
      <div class="check_bar">
        <div
          class="item"
          :class="{ 'sort_1': timetype==1, 'sort_2': timetype==2 }"
          @click="timeBtn(timetype)"
        >发布时间</div>
      </div>
      <Rement :list="rementList" :row="true"></Rement>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        background
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <Buttons :buttons="buttons" @goBack="goBack"></Buttons>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/breadcrumb'
import Rement from './/components/rement'

import { getqserviceRequirement } from "@/common/api/service.js";
export default {
  name: 'service',
  components: { Breadcrumb,Rement },
  data() {
    return {
      buttons:[{text:"返回",size:"l",type:"normal",method:"goBack"}],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      rementList: [],
      crumbs: [
        {
          label: '门户首页',
          value: 'index',
        },
        {
          label: '服务市场',
          value: 'service',
        },
        {
          label: '需求广场',
          value: '',
          choose: true,
        },
      ],
      login: false,
      timetype: null,
      sort: '',
      sortOrder: '',
    }
  },
  methods: {
    // 服务需求列表
    async getqserviceRequirement() {
      let obj = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        sort: this.sort,
        sortOrder: this.sortOrder,
      }
      let res = await getqserviceRequirement(obj)
      console.log('res123', res)
      if (res.status == 200) {
        this.rementList = res.result.records
        this.total = res.result.total
      }
    },
    //进入需求广场详情
    onGetInto(item) {
      if (item != '') {
        localStorage.setItem('DETAILS', JSON.stringify(item))
      }
      this.$router.push('demandDetails')
    },
    /**
     * 改变页面大小事件
     */
    handleSizeChange(e) {
      this.pageSize = e
      this.getqserviceRequirement()
    },
    /**
     * 换页事件
     */
    handleCurrentChange(e) {
      this.pageNum = e
      this.getqserviceRequirement()
    },
    timeBtn(type) {
      console.log('type', type)
      if (!type) {
        this.timetype = 1
        this.sort = 'createTime'
        this.sortOrder = 'asc'
      } else {
        this.timetype = type == 1 ? 2 : 1
        this.sortOrder = type == 1 ? 'desc' : 'asc'
      }
      this.getqserviceRequirement()
    },
    /**
     * 返回上一页
     */
    goBack() {
      this.$router.back()
    },
  },
  mounted() {},
  activated() {},
  created() {
    this.getqserviceRequirement()
  },
}
</script>

<style lang="scss" scoped>
.breadcrumb {
  width: 1200px;
  margin: 20px 0;
}

.two_text {
  word-break: break-all;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.two_text1 {
  word-break: break-all;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.content {
  padding: 10px 0 40px;
  width: 1200px;
  margin: auto;
  text-align: left;
  .check_bar {
    height: 40px;
    background: #f4f4f4;
    border: 1px solid #eeeeee;
    font-size: 14px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    .item {
      margin-right: 32px;
      padding-right: 15px;
      background-repeat: no-repeat;
      background-image: url(../../assets/image/service/icon_11.png);
      background-repeat: no-repeat;
      background-size: 7px;
      background-position: right center;
      cursor: pointer;
      &.sort_1 {
        background-image: url(../../assets/image/service/icon_8.png);
      }
      &.sort_2 {
        background-image: url(../../assets/image/service/icon_9.png);
      }
    }
  }
  ::v-deep .el-pagination {
    text-align: right;
    margin: 40px 0 60px;
  }
  .back_btn {
    width: 120px;
    height: 40px;
    background: #f1f2f4;
    border-radius: 3px;
    color: #045db9;
    font-size: 16px;
    line-height: 40px;
    margin: 40px auto 0;
    text-align: center;
    display: block;
  }
}

.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>
